package ModelLayer;

import java.util.ArrayList;

public class IncomingOrder {
	String orderId;
	Customer c;
	String date;
	String orderStatus;
	String dateSent;
	ArrayList<InPartOrder> partList;
	
	public IncomingOrder(Customer c, String date, String orderStatus, String dateSent, ArrayList<InPartOrder> partList)
	{
		//Constructor using fields as parameters. 
		this.c = c;
		this.date = date;
		this.orderStatus = orderStatus;
		this.dateSent = dateSent;
		this.partList = partList;
	}
	
	public IncomingOrder()
	{
		//Constructor with none parameters
		orderStatus = null;
	}

	public String getOrderId() {
		//Returns orderId
		return orderId;
	}

	public void setOrderId(String orderId) {
		//Set orderId
		this.orderId = orderId;
	}

	public Customer getC() {
		//Returns customer
		return c;
	}

	public void setC(Customer c) {
		//Set customer
		this.c = c;
	}

	public String getDate() {
		//Returns date
		return date;
	}

	public void setDate(String date) {
		//Set date
		this.date = date;
	}

	public String getOrderStatus() {
		//Returns orderStatus
		return orderStatus;
	}

	public void setOrderStatus(String orderStatus) {
		//set orderStatus
		this.orderStatus = orderStatus;
	}

	public String getDateSent() {
		//Returns dateSent
		return dateSent;
	}

	public void setDateSent(String dateSent) {
		//Set dateSent
		this.dateSent = dateSent;
	}

	public ArrayList<InPartOrder> getPartList() {
		//Returns partList
		return partList;
	}

	public void setPartList(ArrayList<InPartOrder> partList) {
		//Set partList
		this.partList = partList;
	}
	
	public String getInfo()
	{
		//Returns a string with all info about the order. The string is created using a StringBuilder.
		StringBuilder sb = new StringBuilder();
    	
    	sb.append("**** Order ID: "+orderId+" ****\n\nStatus: "+orderStatus+"\n\nProduct(s):\n");   	
    	
    	int index = 0;
    	String name = null;
        String id = null;
        String amount = null;
    	while(index < partList.size())
        {      
            if(partList.get(index).getP().checkReturnType()==false)
            {
            	id = partList.get(index).getProductId();
            	name = partList.get(index).getP().getFrozenGood().getName();
            	amount = Integer.toString(partList.get(index).getAmount());
            }
            else
            {
            	id = partList.get(index).getProductId();
            	name = partList.get(index).getP().getBeverage().getName();
            	amount = Integer.toString(partList.get(index).getAmount());
            }
        			
        	String product ="Amount: "+amount+" -- product Id:"+id+" -- name: "+name;
        	sb.append(product);   
        	sb.append('\n');
        	index++;
        }
    	
    	sb.append('\n');
    	
    	sb.append("**** ");
        sb.append("Company ****");
        sb.append('\n');
        
        id = "0000000"+Integer.toString(c.getCustomerId());
        name = c.getCompanyName();
        String address = ""+c.getStreet()+" , "+c.getZipCode()+" "+c.getCity()+" , "+c.getCountry();
        sb.append("Company name: "+name+"  & ID:  "+id);
        sb.append('\n');
        sb.append("Delivery address: "+address);
        
        return sb.toString();        
	}
}